import { constantRoutes, asyncRoutes } from '@/router'

// store.state.permission.route
const state = {
  routes: constantRoutes
}

const mutations = {
  setRoutes(state, otherRoutes) {
    // 路由规则不是累加, 应该基于静态路由去添加用户对应的动态路由
    state.routes = [...constantRoutes, ...otherRoutes]
  }
}

const actions = {
  filterRoutes(context, menus) {
    // 过滤出我能看到的路由规则
    // asyncRoutes, menus
    console.log(asyncRoutes)
    const otherRoutes = asyncRoutes.filter(item => menus.includes(item.children[0].name))
    console.log(otherRoutes, 1111)
    context.commit('setRoutes', otherRoutes)
    return otherRoutes
  }
}

const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
